# import time
# class A:
#     __instance=None
#     def __new__(cls, *args, **kwargs):
#         if not cls.__instance:
#             time.sleep(0.0000001)
#             cls.__instance=super().__new__(cls)
#         return cls.__instance
#
# def func():
#     a=A()
#     print(a)
# from threading import Thread
# for i in range(10):
#     Thread(target=func).start()

import time


class A:
    __instance = None
    from threading import Lock
    lock = Lock()  # 类的静态变量只加载一次,

    def __new__(cls, *args, **kwargs):
        with cls.lock:
            if not cls.__instance:
                time.sleep(0.0000001)
                cls.__instance = super().__new__(cls)
        return cls.__instance


def func():
    a = A()
    print(a)


from threading import Thread

for i in range(10):
    Thread(target=func).start()
